package jomi.fatiasdovos.fatias.parser;

import java.util.*;

/**
 * Created by jorgemachado on 27/12/13.
 */
public class Source {

    public static Map<String,Source> sources = new HashMap<String,Source>();

    String name;
    String url;
    Group group;

    public Source(Properties props,String suffix)
    {
        name = props.getProperty("source." + suffix + ".name");
        url = props.getProperty("source." + suffix + ".url");
        group = Group.groups.get(props.getProperty("source." + suffix + ".group"));

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Group getGroup() {
        return group;
    }

    public void setGroup(Group group) {
        this.group = group;
    }

    public static void initSources(SourcesProperties props)
    {
        Group.initGroups(props);
        if(sources.size() > 0)
            return;
        String[] srcs = SourcesProperties.getProperty("source.active.sources").split(" ");
        for(String src: srcs)
        {
            Source s = new Source(props.getProps(),src);
            sources.put(src,s);
        }
    }
    public static Collection<Source> getSources(SourcesProperties props)
    {
        initSources(props);
        return sources.values();
    }
}
